package com.turnengine.client.global.game.command.gwt;

import static com.javabi.common.dependency.DependencyFactory.getDependency;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.javabi.codebuilder.generated.gwt.IGeneratedRemoteServiceServlet;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.errorcode.gwt.GwtErrorCodeException;
import com.javabi.command.executor.ICommandExecutorService;
import com.turnengine.client.global.game.bean.IGameInstance;
import com.turnengine.client.global.game.command.GetGameInstanceByName;

/**
 * The Get Game Instance By Name Servlet.
 */
public class GetGameInstanceByNameServlet extends RemoteServiceServlet implements IGeneratedRemoteServiceServlet, GetGameInstanceByNameService {

	public IGameInstance getGameInstanceByName(String instanceName, int versionId) throws GwtErrorCodeException {
		GetGameInstanceByName command = new GetGameInstanceByName(instanceName, versionId);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<IGameInstance> response = service.execute(command);
		if (response.hasErrors()) {
			throw new GwtErrorCodeException(response);
		}
		return response.getReturnValue();
	}
}
